package lex.explorer;

import java.awt.BorderLayout;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.border.BevelBorder;

import org.lex.explorer.StatusBar;
import org.lex.swing.Swings;
import org.lex.utils.text.SizeFormat;


public class StatusBar extends javax.swing.JPanel {
	private JLabel infoLabel;
	private JLabel sizeLabel;

	public static void main(String[] args) {
		Swings.show(new StatusBar());
	}

	public StatusBar() {
		super();
		initialize();
	}

	public void setInformation(String info) {
		this.getInfoLabel().setText(info);
	}

	public void setSize(long size) {
		this.getSizeLabel().setText(SizeFormat.autoFormat(size) + "B");
	}

	public void setSize(String size) {
		this.getSizeLabel().setText(size);
	}

	private void initialize() {
		this.setLayout(new BorderLayout());
		this.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
		this.add(getInfoLabel(), BorderLayout.CENTER);
		this.add(getSizeLabel(), BorderLayout.EAST);
	}

	private JLabel getInfoLabel() {
		if (infoLabel == null) {
			infoLabel = new JLabel();
			infoLabel.setText("6 objects");
			infoLabel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
		}
		return infoLabel;
	}

	private JLabel getSizeLabel() {
		if (sizeLabel == null) {
			sizeLabel = new JLabel();
			sizeLabel.setText("2.32 MB");
			sizeLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 6));
		}
		return sizeLabel;
	}
}
